package homework.day03;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

/**
 * 生成10个0-100的随机数并存入一个List集合中并输出
 * 之后将集合第3到第6个元素翻转并输出
 * 
 * @author Xiloer
 *
 */
public class Test04 {
    public static void main(String[] args) {
        Random rd = new Random();
        List<Integer> list = new ArrayList<>();
        //生成10个0-100的随机数并存入一个List集合中并输出
        for (int i = 0; i < 10; i++) {
            list.add(i,rd.nextInt(100));
        }
        System.out.println("随机数集合:"+list);
        //之后将集合第3到第6个元素翻转并输出
        List<Integer> subList = list.subList(2,6);
        //方法一:
        for (int i = 0; i < subList.size()/2; i++) {
            Integer number = subList.get(i);
            number = subList.set(subList.size()-i-1,number);
            subList.set(i,number);
        }
        System.out.println("方法一翻转后:"+subList);
        //方法二:
        Collections.reverse(subList);
        System.out.println("方法二翻转后:"+subList);
    }
}
